home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2913 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.0 KB

  1. Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
  2. From: Bowden Wise <wiseb@cs.rpi.edu>
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++
  4. Subject: Singleton Registry Revisited
  5. Date: 19 Jan 1996 22:55:53 -0000
  6. Organization: Rensselaer Polytechnic Institute, Computer Science
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: vandevod@cs.rpi.edu
  9. Message-ID: <4dp7hp$egd@netlab.cs.rpi.edu>
  10. NNTP-Posting-Host: netlab.cs.rpi.edu
  11. X-Original-Date: Fri, 19 Jan 1996 17:35:30 -0800
  12.  
  13. Thanks to those of you who responded to my query about a hierarchy
  14. of Singletons.  Recall, that my plan is to have a hierarchy of
  15. Singletons.  
  16.  
  17. All of the singletons share some base functionality, which I have
  18. placed in a base class: BaseResource   ... this class is also
  19. abstract, so I can only use BaseResource's as pointers and references.
  20.  
  21. Say we have two resources, derived from that one, 
  22.   class Resource1 : public BaseResource;
  23.   class Resource2 : public BaseResource;
  24.  
  25. I have placed the singleton code in a template class, so that I
  26. can instantiate singleton instances of resources like this:
  27.  
  28.   static Singleton<Resource1> singletonResource1;
  29.   static Singleton<Resource2> singletonResource2;
  30.  
  31. This all works great.  
  32.  
  33. Now, the problem at hand is to implement a SingletonRegistry.
  34. However, I believe I cannot do this since I have separated the
  35. singleton functionality from the base class functionality.  It 
  36. appears to me that I must not use a template to separate the
  37. singleton functionality from the BaseResource class.  Since 
  38. the way it is set up now, there is no way to create a map from
  39. resource names -> resource instances
  40.  
  41. I am going in circles here trying to figure out what I need, here
  42. is some of my ramblings ... 
  43.  
  44. I plan to use the STL map container, and was trying to develop my
  45. map entries:
  46.  
  47.    typedef map < string, Singleton<BaseResource&>* > MyMap;
  48.  
  49. but I dont think this will work, since the above Singletons
  50. are not derived from a Singleton<BaseResource>
  51.  
  52. Maybe what I need instead is to make the singletons like this:
  53.  
  54.   typedef map < string, Singleton<BaseResource*>* > MyMap
  55.  
  56. and then 
  57.  
  58. when a concrete singleton resource is created, such as the, 
  59. Singleton<Resource1> have it register itself like this in the 
  60. constructor perhaps:
  61.  
  62. Singleton<Resource1>::Singleton<Resource1>
  63. {
  64.    // but I cannot access the base part of Resource1 from here ??
  65.    // so no way to call 
  66.    // this is not what we want since it is not derived from
  67.    // Singleton<BaseaResource*>
  68.    registry.Register ("Resource1",  this );
  69. }   
  70.    
  71. Any ideas anyone?  I'll keep thinking ... 
  72. Bowden
  73.  
  74. --------------------------------------------------------------------
  75. G. Bowden Wise
  76. Computer Science Dept, Rensselaer Polytechnic Inst, Troy, NY 12180
  77. Email: wiseb@cs.rpi.edu         WWW: http://www.cs.rpi.edu/~wiseb/
  78.  
  79.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  80.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  81.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  82.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  83.